Namespace Datos
    Public Class clTablaGenerica
        <ThreadStatic()> Friend Shared cnnShared As Data.IDbConnection
        <ThreadStatic()> Friend Shared _confIdioma As clConfIdioma
        Dim cnn As Data.IDbConnection
        Dim idioma As New clConfIdioma
        Dim _tabla As String
        Protected _modificado As Boolean = False
        Protected _nuevo As Boolean = True
        'Dim _hijo As Object
        Dim _listaObjetosBase As System.Collections.Generic.List(Of camposAtributos)
        Dim _llavePrimaria As System.Collections.Generic.List(Of camposAtributos)
        Dim _llavesForaneas As System.Collections.Generic.List(Of camposAtributos)
        'Dim _tipoDato As Type
        Dim _gui As System.Guid

        Public Sub New(ByVal nombreTabla As String, ByVal tipoDato As Type, Optional ByVal confIdioma As clConfIdioma = Nothing)
            If confIdioma Is Nothing Then confIdioma = getidioma 'crea la clase que extraee los datos para ver si hay un idioma alterno
            _confIdioma = confIdioma
            _tabla = nombreTabla
            '_tipoDato = tipoDato
            'getMiembros()

        End Sub
        Public Sub New(ByVal cnn As Data.IDbConnection, ByVal nombreTabla As String, ByVal tipoDato As Type, Optional ByVal confIdioma As clConfIdioma = Nothing)
            If confIdioma Is Nothing Then confIdioma = getidioma
            _confIdioma = confIdioma
            Me.cnn = cnn
            _tabla = nombreTabla
            '_tipoDato = tipoDato
            'getMiembros()
        End Sub

#Region "Llaves y Miembros"
        Public Function getLlavePrimaria() As System.Collections.Generic.List(Of camposAtributos)
            If _llavePrimaria Is Nothing Then
                Dim cb As camposAtributos
                _llavePrimaria = New System.Collections.Generic.List(Of camposAtributos)
                For Each cb In _listaObjetosBase
                    If cb.Atributo.Tipo = enTipoCampoBase.parteLlavePrimaria Then
                        _llavePrimaria.Add(cb)
                    End If
                Next
            End If
            Return _llavePrimaria
        End Function
        Private Function getLlavesForaneas() As System.Collections.Generic.List(Of camposAtributos)
            If _llavesForaneas Is Nothing Then
                Dim cb As camposAtributos
                _llavesForaneas = New System.Collections.Generic.List(Of camposAtributos)
                For Each cb In _listaObjetosBase
                    If cb.Atributo.Tipo = enTipoCampoBase.llaveForanea Then
                        _llavesForaneas.Add(cb)
                    End If
                Next
            End If
            Return _llavesForaneas
        End Function
        Private Sub getMiembros(ByVal hijo As Object)
            Dim p As System.Reflection.PropertyInfo
            Dim att As definicionBaseAttribute
            _listaObjetosBase = New System.Collections.Generic.List(Of camposAtributos)
            For Each p In hijo.GetType.GetProperties(Reflection.BindingFlags.Public Or Reflection.BindingFlags.Instance)
                att = DirectCast(Attribute.GetCustomAttribute(p, GetType(definicionBaseAttribute)), definicionBaseAttribute)
                If att Is Nothing = False Then
                    'en caso sea un campo de solo lectura hay que asignar el valor directamente al field!!!!!!
                    If p.CanWrite = False Or att.fieldSoloLectura Is Nothing = False Then
                        Dim f As System.Reflection.FieldInfo
                        'si no hay filed solo de lectura se utiliza el mismo campo de la propiedad con guion bajo
                        If att.fieldSoloLectura Is Nothing Then
                            f = hijo.GetType.GetField("_" & p.Name, Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.Public Or Reflection.BindingFlags.IgnoreCase)

                        Else
                            'LA MIERDA NO REGRESABA NADA SI LE PONIA ALGUN BIDING FLAG CUANDO BUSCABA LA LLAVE PRIMARIA (FIELD)
                            f = hijo.GetType.GetField(att.fieldSoloLectura, Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.Public Or Reflection.BindingFlags.IgnoreCase)

                        End If
                        _listaObjetosBase.Add(New camposAtributos(p, att, f))
                    Else
                        _listaObjetosBase.Add(New camposAtributos(p, att))
                    End If
                End If
            Next
        End Sub
#End Region

#Region "Propiedades"
        Public ReadOnly Property nombreTabla() As String
            Get
                Return _tabla
            End Get
        End Property
        Public ReadOnly Property ListaObjetosParaBase() As System.Collections.Generic.List(Of camposAtributos)
            Get
                Return _listaObjetosBase
            End Get
        End Property

        Public ReadOnly Property Modificado() As Boolean
            Get
                Return _modificado
            End Get
        End Property
        Public ReadOnly Property Nuevo() As Boolean
            Get
                Return _nuevo
            End Get
        End Property
        Public Shared ReadOnly Property hayConexionShared() As Boolean
            Get
                If cnnShared Is Nothing = False Then
                    Return True
                Else
                    Return False
                End If
            End Get
        End Property

        Public ReadOnly Property getConexion() As Data.IDbConnection
            Get
                If cnn Is Nothing = False Then
                    Return cnn
                Else
                    Return cnnShared
                End If
            End Get
        End Property
        Public Shared Property setConexion() As Data.IDbConnection
            Get
                Return cnnShared
            End Get
            Set(ByVal value As Data.IDbConnection)
                cnnShared = value
            End Set
        End Property
        Public Shared Property setIdioma() As clConfIdioma
            Get
                Return _confIdioma
            End Get
            Set(ByVal value As clConfIdioma)
                _confIdioma = value
            End Set
        End Property
        Public ReadOnly Property getidioma() As clConfIdioma
            Get
                If _confIdioma Is Nothing = False Then
                    Return _confIdioma
                Else
                    Return idioma
                End If
            End Get
        End Property
#End Region
        'Public Sub setConexionInstancia(ByVal cnn As Data.IDbConnection)
        '    Me.cnn = cnn
        'End Sub
        Protected Sub cargarDatosInterno(ByVal hijo As Object)
            Dim cerrar As Boolean = False
            Dim cnn As Data.IDbConnection = getConexion
            _confIdioma = getidioma
            If cnn.State = ConnectionState.Closed Then
                cerrar = True
                cnn.Open()
            End If
            getMiembros(hijo)
            'inicializa command dependiendo del tip de conexion
            Dim cmd As Data.IDbCommand
            If TypeOf cnn Is SqlClient.SqlConnection Then
                cmd = New SqlClient.SqlCommand(crearSelect, getConexion)
            ElseIf TypeOf cnn Is OracleClient.OracleConnection Then
                cmd = New OracleClient.OracleCommand(crearSelect, getConexion)
            ElseIf TypeOf cnn Is MySql.Data.MySqlClient.MySqlConnection Then
                cmd = New MySql.Data.MySqlClient.MySqlCommand(crearSelect, getConexion)
            Else
                Throw New Exception("Tipo de cliente de datos no soportado aun")
            End If

            agregarParametrosPK(cmd, hijo)

            Dim lector As Data.IDataReader = cmd.ExecuteReader
            Dim i As Integer
            If lector.Read Then
                For i = 0 To lector.FieldCount - 1
                    _confIdioma.setDatoString(hijo, _listaObjetosBase(i), lector(i))
                    '_listaObjetosBase(i).setData(hijo, lector(i))
                Next
                _nuevo = False
                _modificado = False
            Else
                _nuevo = True
                _modificado = False
            End If
            lector.Close()

            If cerrar Then cnn.Close()
        End Sub
        Protected Sub guardarDatosInterno(ByVal hijo As Object)
            If _nuevo = True Or _modificado = True Then
                Dim cerrar As Boolean = False
                Dim cnn As Data.IDbConnection = getConexion
                If cnn.State = ConnectionState.Closed Then
                    cerrar = True
                    cnn.Open()
                End If
                getMiembros(hijo)
                'inicializa command dependiendo del tipo de conexion
                Dim cmd As Data.IDbCommand
                If TypeOf cnn Is SqlClient.SqlConnection Then
                    cmd = New SqlClient.SqlCommand()
                ElseIf TypeOf cnn Is OracleClient.OracleConnection Then
                    cmd = New OracleClient.OracleCommand()
                ElseIf TypeOf cnn Is MySql.Data.MySqlClient.MySqlConnection Then
                    cmd = New MySql.Data.MySqlClient.MySqlCommand()
                Else
                    Throw New Exception("Tipo de cliente de datos no soportado aun")
                End If
                cmd.Connection = getConexion

                If _nuevo = True Then
                    cmd.CommandText = crearInsert()

                    agregarParametrosInserUpdt(cmd, hijo)
                    Dim ident As Integer
                    If TypeOf cmd Is SqlClient.SqlCommand Then
                        'cmd.Transaction = cmd.Connection.BeginTransaction
                        ident = cmd.ExecuteScalar
                        setIdent(ident, hijo)
                    ElseIf TypeOf cnn Is OracleClient.OracleConnection Then
                        cmd.ExecuteNonQuery()
                        setIdentOra(hijo)
                    ElseIf TypeOf cnn Is MySql.Data.MySqlClient.MySqlConnection Then
                        ident = cmd.ExecuteScalar
                        setIdentMySQL(ident, hijo)
                    Else
                        Throw New Exception("Tipo de cliente de datos no soportado aun")
                    End If
                ElseIf _modificado = True Then
                    cmd.CommandText = crearUpdate()
                    agregarParametrosInserUpdt(cmd, hijo, True)
                    agregarParametrosPK(cmd, hijo)
                    cmd.ExecuteNonQuery()
                End If

                _nuevo = False
                _modificado = False
            End If
            
        End Sub
        Private Sub setIdentMySQL(ByVal ident As Integer, ByVal hijo As Object)
            Dim cb As camposAtributos
            For Each cb In getLlavePrimaria()
                If cb.Atributo.Tipo = enTipoCampoBase.parteLlavePrimaria And (cb.Propiedad.CanWrite = False Or cb.Atributo.fieldSoloLectura Is Nothing = False) Then
                    cb.setData(hijo, ident)
                End If
            Next

        End Sub
        Private Sub setIdentOra(ByVal hijo As Object)
            Dim aux As Decimal = 0
            Dim cb As camposAtributos
            For Each cb In getLlavePrimaria()
                If cb.Atributo.Tipo = enTipoCampoBase.parteLlavePrimaria And cb.Atributo.fieldSoloLectura Is Nothing = False AndAlso cb.Atributo.NombreSeq Is Nothing = False Then 'se utiliza el fielsololectura para saber si la propiedad es solo de lectura. No se pued utilizar el can write ya que en la clCapadatos las propiedades de campos autonumericos no pueden ser readonly.
                    Dim cmd As New OracleClient.OracleCommand("select " & cb.Atributo.NombreSeq & ".currval from dual", getConexion)
                    aux = cmd.ExecuteScalar
                    cb.setData(hijo, aux)
                End If
            Next

        End Sub
        Private Sub setIdent(ByVal ident As Integer, ByVal hijo As Object)
            Dim cb As camposAtributos
            For Each cb In getLlavePrimaria()
                If cb.Atributo.Tipo = enTipoCampoBase.parteLlavePrimaria And (cb.Propiedad.CanWrite = False Or cb.Atributo.fieldSoloLectura Is Nothing = False) Then
                    cb.setData(hijo, ident)
                End If
            Next
        End Sub
        Protected Sub borrarInterno(ByVal hijo As Object)
            If _nuevo = False Then
                Dim cerrar As Boolean = False
                Dim cnn As Data.IDbConnection = getConexion
                If cnn.State = ConnectionState.Closed Then
                    cerrar = True
                    cnn.Open()
                End If
                Dim cmd As Data.IDbCommand
                If TypeOf cnn Is SqlClient.SqlConnection Then
                    cmd = New SqlClient.SqlCommand()
                ElseIf TypeOf cnn Is OracleClient.OracleConnection Then
                    cmd = New OracleClient.OracleCommand()
                ElseIf TypeOf cnn Is MySql.Data.MySqlClient.MySqlConnection Then
                    cmd = New MySql.Data.MySqlClient.MySqlCommand()
                Else
                    Throw New Exception("Tipo de cliente de datos no soportado aun")
                End If
                cmd.Connection = getConexion
                cmd.CommandText = "delete from " & _tabla & " where " & generarFiltroPK()
                agregarParametrosPK(cmd, hijo)
                cmd.ExecuteNonQuery()
                If cerrar Then cnn.Close()
            End If
        End Sub

        '<Obsolete()> _
        'Private Sub agregarParametrosInserUpdt(ByRef cmd As Data.IDbCommand, ByVal hijo As Object, Optional ByVal esUpdate As Boolean = False)
        '    Dim cb As camposAtributos
        '    For Each cb In _listaObjetosBase
        '        If (cb.Propiedad.CanWrite And esUpdate = False) OrElse (cb.Propiedad.CanWrite And cb.Atributo.Tipo <> enTipoCampoBase.parteLlavePrimaria) AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then
        '            If TypeOf getConexion Is SqlClient.SqlConnection Then
        '                CType(cmd, SqlClient.SqlCommand).Parameters.Add("@" & cb.Atributo.nombreCampoBase, transformacionTiposSqlClient(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
        '            ElseIf TypeOf getConexion Is OleDb.OleDbConnection Then
        '                CType(cmd, OleDb.OleDbCommand).Parameters.Add("@" & cb.Atributo.nombreCampoBase, transformacionTiposOleDb(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
        '            End If
        '        End If
        '    Next
        'End Sub

        '<Obsolete()> _
        'Private Sub agregarParametrosPK(ByRef cmd As Data.IDbCommand, ByVal hijo As Object)
        '    Dim cb As camposAtributos
        '    For Each cb In getLlavePrimaria()
        '        If TypeOf getConexion Is SqlClient.SqlConnection Then
        '            CType(cmd, SqlClient.SqlCommand).Parameters.Add("@" & cb.Atributo.nombreCampoBase, transformacionTiposSqlClient(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
        '        ElseIf TypeOf getConexion Is OleDb.OleDbConnection Then
        '            CType(cmd, OleDb.OleDbCommand).Parameters.Add("@" & cb.Atributo.nombreCampoBase, transformacionTiposOleDb(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
        '        End If
        '    Next
        'End Sub

        Friend Sub agregarParametrosInserUpdt(ByRef cmd As Data.IDbCommand, ByVal hijo As Object, Optional ByVal esUpdate As Boolean = False)
            Dim cb As camposAtributos
            For Each cb In _listaObjetosBase
                If (cb.Propiedad.CanWrite And esUpdate = False And cb.Atributo.fieldSoloLectura Is Nothing) OrElse (cb.Propiedad.CanWrite And cb.Atributo.Tipo <> enTipoCampoBase.parteLlavePrimaria And cb.Atributo.fieldSoloLectura Is Nothing) Then 'se acaba de agregar la validacion del fiel solo lectura a la segunda parte del ORELSE
                    If TypeOf getConexion Is SqlClient.SqlConnection Then
                        CType(cmd, SqlClient.SqlCommand).Parameters.Add("@" & cb.Atributo.nombreCampoBase, clTablaGenerica.transformacionTiposSqlClient(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
                    ElseIf TypeOf getConexion Is OracleClient.OracleConnection Then
                        'Modificado Rafaella linnea comentariada es la original
                        'CType(cmd, OleDb.OleDbCommand).Parameters.Add("@" & cb.Atributo.nombreCampoBase, clTablaGenerica.transformacionTiposOleDb(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
                        CType(cmd, OracleClient.OracleCommand).Parameters.Add(":" & cb.Atributo.nombreCampoBase, clTablaGenerica.transformacionTiposOracleClient(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
                    ElseIf TypeOf getConexion Is MySql.Data.MySqlClient.MySqlConnection Then
                        CType(cmd, MySql.Data.MySqlClient.MySqlCommand).Parameters.Add("?" & cb.Atributo.nombreCampoBase, clTablaGenerica.transformacionTiposMySQL(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
                    End If
                End If
            Next
        End Sub
        Friend Sub agregarParametrosPK(ByRef cmd As Data.IDbCommand, ByVal hijo As Object)
            Dim cb As camposAtributos
            For Each cb In getLlavePrimaria()
                If TypeOf getConexion Is SqlClient.SqlConnection Then
                    CType(cmd, SqlClient.SqlCommand).Parameters.Add("@" & cb.Atributo.nombreCampoBase, clTablaGenerica.transformacionTiposSqlClient(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
                ElseIf TypeOf getConexion Is OracleClient.OracleConnection Then
                    CType(cmd, OracleClient.OracleCommand).Parameters.Add(":" & cb.Atributo.nombreCampoBase, clTablaGenerica.transformacionTiposOracleClient(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
                ElseIf TypeOf getConexion Is MySql.Data.MySqlClient.MySqlConnection Then
                    CType(cmd, MySql.Data.MySqlClient.MySqlCommand).Parameters.Add("?" & cb.Atributo.nombreCampoBase, clTablaGenerica.transformacionTiposMySQL(cb.Propiedad.PropertyType)).Value = cb.getData(hijo)
                End If
            Next
        End Sub

        'Private Function crearUpdate() As String
        '    Dim cb As camposAtributos
        '    Dim aux As String = "update " & _tabla & " set "
        '    For Each cb In _listaObjetosBase
        '        If cb.Propiedad.CanWrite Then aux &= cb.Atributo.nombreCampoBase & "=@" & cb.Atributo.nombreCampoBase & ","
        '    Next
        '    aux = aux.Substring(0, aux.Length - 1) & " where " & generarFiltroPK()
        '    Return aux
        'End Function
        'Private Function crearInsert() As String
        '    Dim cb As camposAtributos
        '    Dim aux As String = "insert into " & _tabla & "("
        '    For Each cb In _listaObjetosBase
        '        If cb.Propiedad.CanWrite AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then
        '            aux &= cb.Atributo.nombreCampoBase & ","
        '        End If
        '    Next
        '    'aux &= " unicoID,"
        '    aux = aux.Substring(0, aux.Length - 1) & ") values ("

        '    'insertar parametros
        '    For Each cb In _listaObjetosBase
        '        If cb.Propiedad.CanWrite AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then
        '            aux &= "@" & cb.Atributo.nombreCampoBase & ","
        '        End If
        '    Next
        '    'aux &= "@unicoID,"
        '    aux = aux.Substring(0, aux.Length - 1) & ");"
        '    If TypeOf getConexion Is SqlClient.SqlConnection Then
        '        aux &= "select isnull(@@identity,0);"
        '    End If
        '    Return aux
        'End Function
        'Private Function crearSelect() As String
        '    Dim cb As camposAtributos
        '    Dim aux As String = "select "
        '    For Each cb In _listaObjetosBase
        '        aux &= cb.Atributo.nombreCampoBase & ", "
        '    Next
        '    aux = aux.Substring(0, aux.Length - 2)
        '    aux &= " from " & nombreTabla
        '    aux &= " where " & generarFiltroPK()
        '    Return aux
        'End Function
        'Private Function generarFiltroPK() As String
        '    Dim cb As camposAtributos
        '    Dim aux As String
        '    For Each cb In getLlavePrimaria()
        '        aux &= String.Format(" {0}={1} and ", cb.Atributo.nombreCampoBase, "@" & cb.Atributo.nombreCampoBase)
        '    Next
        '    aux = aux.Substring(0, aux.Length - 4)
        '    Return aux
        'End Function
        Private Function crearUpdate() As String
            Dim cb As camposAtributos
            Dim aux As String = "update " & _tabla & " set "
            If TypeOf getConexion Is SqlClient.SqlConnection Then
                For Each cb In _listaObjetosBase
                    If cb.Propiedad.CanWrite AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then aux &= cb.Atributo.nombreCampoBase & "=@" & cb.Atributo.nombreCampoBase & ","
                Next
            ElseIf TypeOf getConexion Is OracleClient.OracleConnection Then
                For Each cb In _listaObjetosBase
                    If cb.Propiedad.CanWrite AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then aux &= cb.Atributo.nombreCampoBase & "=:" & cb.Atributo.nombreCampoBase & ","
                Next
            ElseIf TypeOf getConexion Is MySql.Data.MySqlClient.MySqlConnection Then
                For Each cb In _listaObjetosBase
                    If cb.Propiedad.CanWrite AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then aux &= cb.Atributo.nombreCampoBase & "=?" & cb.Atributo.nombreCampoBase & ","
                Next
            End If

            aux = aux.Substring(0, aux.Length - 1) & " where " & generarFiltroPK()
            Return aux
        End Function
        Private Function crearInsert() As String
            Dim cb As camposAtributos
            Dim aux As String = "insert into " & _tabla & "("
            For Each cb In _listaObjetosBase
                If cb.Propiedad.CanWrite AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then
                    aux &= cb.Atributo.nombreCampoBase & ","
                End If
            Next
            aux = aux.Substring(0, aux.Length - 1) & ") values ("

            'insertar parametros
            '*************Modificado Rafael*****************************
            If TypeOf getConexion Is SqlClient.SqlConnection Then
                For Each cb In _listaObjetosBase
                    If cb.Propiedad.CanWrite AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then
                        aux &= "@" & cb.Atributo.nombreCampoBase & ","
                    End If
                Next
            ElseIf TypeOf getConexion Is OracleClient.OracleConnection Then
                For Each cb In _listaObjetosBase
                    If cb.Propiedad.CanWrite AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then
                        aux &= ":" & cb.Atributo.nombreCampoBase & ","
                    End If
                Next
            ElseIf TypeOf getConexion Is MySql.Data.MySqlClient.MySqlConnection Then
                For Each cb In _listaObjetosBase
                    If cb.Propiedad.CanWrite AndAlso cb.Atributo.fieldSoloLectura Is Nothing Then
                        aux &= "?" & cb.Atributo.nombreCampoBase & ","
                    End If
                Next
            End If

            aux = aux.Substring(0, aux.Length - 1) & ")"
            If TypeOf getConexion Is SqlClient.SqlConnection Then
                aux &= ";select isnull(scope_identity() ,0)"
            ElseIf TypeOf getConexion Is MySql.Data.MySqlClient.MySqlConnection Then
                aux &= ";SELECT LAST_INSERT_ID()"
            End If

            Return aux
        End Function
        Private Function crearSelect() As String
            Dim cb As camposAtributos
            Dim aux As String = "select "
            For Each cb In _listaObjetosBase
                aux &= cb.Atributo.nombreCampoBase & ", "
            Next
            aux = aux.Substring(0, aux.Length - 2)
            aux &= " from " & _tabla
            aux &= " where " & generarFiltroPK()
            Return aux
        End Function
        Private Function generarFiltroPK() As String
            Dim cb As camposAtributos
            Dim aux As String
            Dim cnn As Data.IDbConnection = getConexion
            For Each cb In getLlavePrimaria()
                If TypeOf cnn Is SqlClient.SqlConnection Then
                    aux &= String.Format(" {0}={1} and ", cb.Atributo.nombreCampoBase, "@" & cb.Atributo.nombreCampoBase)
                ElseIf TypeOf cnn Is OracleClient.OracleConnection Then
                    aux &= String.Format(" {0}={1} and ", cb.Atributo.nombreCampoBase, ":" & cb.Atributo.nombreCampoBase)
                ElseIf TypeOf cnn Is MySql.Data.MySqlClient.MySqlConnection Then
                    aux &= String.Format(" {0}={1} and ", cb.Atributo.nombreCampoBase, "?" & cb.Atributo.nombreCampoBase)

                End If

            Next
            aux = aux.Substring(0, aux.Length - 4)
            Return aux
        End Function


#Region "Transformacion Tipo DatosPropiedades/Parametros"
        Shared Function transformacionTiposOleDb(ByVal tipo As Type) As OleDb.OleDbType
            Select Case tipo.Name
                Case "Double"
                    Return Data.OleDb.OleDbType.Double
                Case "Int32"
                    Return Data.OleDb.OleDbType.Integer
                Case "String"
                    Return Data.OleDb.OleDbType.VarChar
                Case "Boolean"
                    Return Data.OleDb.OleDbType.Boolean
                Case "Byte"
                    Return Data.OleDb.OleDbType.SmallInt
                Case "DateTime"
                    Return Data.OleDb.OleDbType.Date
                Case "Int16"
                    Return Data.OleDb.OleDbType.SmallInt
                Case "int64"
                    Return Data.OleDb.OleDbType.BigInt
                Case "Single"
                    Return Data.OleDb.OleDbType.Single
                Case "Decimal"
                    Return Data.OleDb.OleDbType.Decimal
                Case Else
                    Throw New clErrorPersonalizado("Ese tipo de dato no se puede conevrtir a dato OLEDB")
            End Select
        End Function
        Shared Function transformacionTiposOracleClient(ByVal tipo As Type) As OracleClient.OracleType
            Select Case tipo.Name
                Case "Double"
                    Return OracleClient.OracleType.Double
                Case "Int32"
                    Return OracleClient.OracleType.Int32
                Case "String"
                    Return OracleClient.OracleType.VarChar
                Case "Boolean"
                    Return OracleClient.OracleType.Byte
                Case "Byte"
                    Return OracleClient.OracleType.Byte
                Case "DateTime"
                    Return OracleClient.OracleType.DateTime
                Case "Int16"
                    Return OracleClient.OracleType.Int16
                Case "int64"
                    Return OracleClient.OracleType.Number
                Case "Single"
                    Return OracleClient.OracleType.Number
                Case "Decimal"
                    Return OracleClient.OracleType.Number
                Case Else
                    Throw New clErrorPersonalizado("Ese tipo de dato no se puede conevrtir a dato OLEDB")
            End Select

        End Function
        Shared Function transformacionTiposMySQL(ByVal tipo As Type) As MySql.Data.MySqlClient.MySqlDbType
            Select Case tipo.Name
                Case "Double"
                    Return MySql.Data.MySqlClient.MySqlDbType.Double
                Case "Int32"
                    Return MySql.Data.MySqlClient.MySqlDbType.Int32
                Case "String"
                    Return MySql.Data.MySqlClient.MySqlDbType.String
                Case "Boolean"
                    Return MySql.Data.MySqlClient.MySqlDbType.Bit
                Case "Byte"
                    Return MySql.Data.MySqlClient.MySqlDbType.Byte
                Case "DateTime"
                    Return MySql.Data.MySqlClient.MySqlDbType.Datetime
                Case "Int16"
                    Return MySql.Data.MySqlClient.MySqlDbType.Int16
                Case "int64"
                    Return MySql.Data.MySqlClient.MySqlDbType.Int64
                Case "Single"
                    Return MySql.Data.MySqlClient.MySqlDbType.Double
                Case "Decimal"
                    Return MySql.Data.MySqlClient.MySqlDbType.Decimal
                Case Else
                    Throw New clErrorPersonalizado("Ese tipo de dato no se puede conevrtir a dato OLEDB")
            End Select
        End Function


        Shared Function transformacionTiposSqlClient(ByVal tipo As Type) As SqlDbType
            Select Case tipo.Name
                Case "Double"
                    Return SqlDbType.Decimal
                Case "Int32"
                    Return SqlDbType.Int
                Case "String"
                    Return SqlDbType.VarChar
                Case "Boolean"
                    Return SqlDbType.Bit
                Case "Byte"
                    Return SqlDbType.TinyInt
                Case "DateTime"
                    Return SqlDbType.DateTime
                Case "Int16"
                    Return SqlDbType.SmallInt
                Case "Int64"
                    Return SqlDbType.BigInt
                Case "Single"
                    Return SqlDbType.Float
                Case "Decimal"
                    Return SqlDbType.Decimal
                Case Else
                    Throw New clErrorPersonalizado("Ese tipo de dato no se puede conevrtir a dato a un dato de SQL Server")
            End Select
        End Function
#End Region

    End Class
End Namespace

